package com.sanri.test.testmybatis.po.typehandler;

import com.sanri.test.testmybatis.enums.BatchStatus;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BatchStatusHandler extends BaseTypeHandler<BatchStatus> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, BatchStatus parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i,parameter.getCode());
    }

    @Override
    public BatchStatus getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return BatchStatus.parser(rs.getString(columnName));
    }

    @Override
    public BatchStatus getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return BatchStatus.parser(rs.getString(columnIndex));
    }

    @Override
    public BatchStatus getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return BatchStatus.parser(cs.getString(columnIndex));
    }
}
